//
//  BZBundleResourcesKit.m
//  BZBundleKit
//
//  Created by quheng on 2017/9/20.
//  Copyright © 2017年 quheng. All rights reserved.
//

#import "BZBundleResourcesKit.h"
#import <UIKit/UIKit.h>
#import "BZImageKit.h"

@interface BZBundleResourcesKit()

@property (nonatomic, copy  ) NSString    *bundlePath;
@property (nonatomic, strong) BZImageKit  *imageKit;


@end

@implementation BZBundleResourcesKit


- (BZImageKit *)imageKit{

    if (!_imageKit) {
        _imageKit = [[BZImageKit alloc]init];
    }
    return _imageKit;
}


+ (UIImage *)imageWithName:(NSString *)imageName
                      type:(NSString *)type
                  inBundle:(NSString *)bundlePath
               inDirectory:(NSString *)directory{

    NSParameterAssert(imageName);
    NSParameterAssert(type);
    
    return [BZImageKit imageWithName:imageName type:type inBundle:bundlePath inDirectory:directory];
}


+ (UIImage *)imageWithName:(NSString *)imageName
                      type:(NSString *)type
                bundleName:(NSString *)bundleName
               inDirectory:(NSString *)directory{

    NSParameterAssert(imageName);
    NSParameterAssert(type);
    NSParameterAssert(bundleName);
    
    NSString *bundlePath = [[NSBundle mainBundle]pathForResource:bundleName ofType:@"bundle"];
    
    return [BZImageKit imageWithName:imageName type:type inBundle:bundlePath inDirectory:directory];
    
}


- (void)setBundle:(NSString *)bundleName inDirectory:(NSString *)directory{

    NSParameterAssert(bundleName);
    
    NSString *bundlePath = [[NSBundle mainBundle]pathForResource:bundleName ofType:@"bundle"];
    if (!self.bundlePath) {
        self.bundlePath = [directory length]?[bundlePath stringByAppendingPathComponent:directory]:bundlePath;
    }
}




- (UIImage *)imageWithName:(NSString *)imageName
                      type:(NSString *)type{

    self.imageKit.bundlePath = self.bundlePath;
    return [self.imageKit imageWithName:imageName type:type];

}

@end
